package com.za.wbw.util;

import java.io.File;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class DBListener implements ServletContextListener, ApplicationContextAware{

	@Override
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		// TODO Auto-generated method stub
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
	}
	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		try
		{
			File file = new File("E:\\wbw\\db\\wbw_bak.sql");
			if(file.exists()){
				String cmd = "cmd /c start E:\\wbw\\db\\mysql.bat";
				Process process = Runtime.getRuntime().exec(cmd); 
				process.waitFor();
			}
		}
		catch(Exception ex){
		}
	}
}
